package ControllerUpdate

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"test/ControllerConnct"
	"test/middleware"
	"test/utils"
)

func Update() {
	//连接
	db := ControllerConnct.Connection()

	//路由以及中间键
	r := gin.Default()
	r.Use(middleware.CORSMiddleware())

	//定义变量
	var (
		studentid   string
		studentname string
		classid     string
		deptid      string
		deptname    string
	)
	//put--> 修改
	r.PUT("/database/MB-TI", func(c *gin.Context) {
		//数据传导
		studentno = c.PostForm("stu_id")
		studentname = c.PostForm("stu_name")
		classid = c.PostForm("class_id")
		deptid = c.PostForm("dept_id")
		deptname = c.PostForm("dept_name")

		fmt.Println(studentid)
		fmt.Println(studentname)
		fmt.Println(classid)
		fmt.Println(classnum)
		fmt.Println(deptid)
		fmt.Println(deptname)

		//Classes := models.Class{
		//	Class_no:  classno,
		//	Class_num: classnum,
		//	Dept_no:   deptno,
		//}
		//Depts := models.Dept{
		//	Dept_no:    deptno,
		//	Dept_name:  deptname,
		//	College_no: collegeno,
		//}
		//Colleges := models.College{
		//	College_no:   collegeno,
		//	College_name: collegename,
		//}
		//TestMs := models.TestM{
		//	Test_no:     testno,
		//	Test_result: testresult,
		//	Student_no:  studentno,
		//}

		//更新操作
		//学生
		db.Table("students").Where("studentno = ?", studentno).Update("studentame", studentname)
		db.Table("students").Where("studentno = ?", studentno).Update("studentsex", studentsex)
		db.Table("students").Where("studentno = ?", studentno).Update("classno", classno)
		//class
		//db.Model(&Classes).Select("Class_no").Updates(map[string]interface{}{"Class_no": classno})
		//db.Model(&Classes).Select("Class_num").Updates(map[string]interface{}{"Class_num": classnum})
		//db.Model(&Classes).Select("Dept_no").Updates(map[string]interface{}{"Dept_no": deptno})
		////dept
		//db.Model(&Depts).Select("Dept_no").Updates(map[string]interface{}{"Dept_no": deptno})
		//db.Model(&Depts).Select("Dept_name").Updates(map[string]interface{}{"Dept_name": deptname})
		//db.Model(&Depts).Select("College_no").Updates(map[string]interface{}{"College_no": collegename})
		////college
		//db.Model(&Colleges).Select("College_no").Updates(map[string]interface{}{"College_no": collegeno})
		//db.Model(&Colleges).Select("College_name").Updates(map[string]interface{}{"College_name": collegename})
		////testms
		//db.Model(&TestMs).Select("Test_no").Updates(map[string]interface{}{"Test_no": testno})
		//db.Model(&TestMs).Select("Test_result").Updates(map[string]interface{}{"Test_result": testresult})
		//db.Model(&TestMs).Select("Student_no").Updates(map[string]interface{}{"Student_no": studentno})

		c.JSON(http.StatusOK, utils.Result{
			Code:    utils.SUCCESS,
			Message: "修改成功！",
		})
	})

	err := r.Run(":8099")
	if err != nil {
		return
	}
}
